//
//  GetMyCommentViewModel.m
//  GuShiNews
//
//  Created by 丁一 on 2019/8/20.
//  Copyright © 2019 Jones. All rights reserved.
//

#import "GetMyCommentViewModel.h"
#import "HJonesNetting.h"
#import "OSSTestMacros.h"
#import "CommentModel.h"
#import "HiJonesClass.h"
#import "SensitiveWordTools.h"

@implementation GetMyCommentViewModel

- (instancetype)init:(id)responseObject{
    if (self = [super init]) {
        
        [HJonesNetting JonesNetting_POST:responseObject
                                  andURL:App_My_Comment_List
                              andtimeout:20.0
                                finished:^(NSError * _Nonnull error, NSDictionary * _Nonnull resultDict) {
                                    if (error) {
                                        [SVProgressHUD showErrorWithStatus:@"网络加载失败"];
                                        [self.delegate GetMyCommentSucces:0 array:nil page:0];
                                    }else{
                                        if ([[resultDict objectForKey:@"Code"] longLongValue]==1000) {
                                            
                                            NSMutableArray *hudonglist = [CommentModel mj_objectArrayWithKeyValuesArray:[resultDict objectForKey:@"CommentArray"]];
                                            
                                            [hudonglist enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                                                CommentModel *linmodel = (CommentModel *)obj;
                                                linmodel.comment = [[SensitiveWordTools sharedInstance]filter:linmodel.comment];
                                                linmodel.comment_height = [HiJonesClass getContent:linmodel.comment width:RECRWITCH-70 font:[UIFont systemFontOfSize:15] jianju:3];
                                                
                                                NSString *linstr = linmodel.news_tittle;
           
                                                linmodel.t_comment = linstr;
                                                linmodel.to_comment_height = [HiJonesClass getContent:linstr width:RECRWITCH-120 font:[UIFont systemFontOfSize:13] jianju:3]+15;
                                            }];
                                            
                                            [self.delegate GetMyCommentSucces:1 array:hudonglist page:[[resultDict objectForKey:@"Page"] intValue]];
                                        }else{
                                            [SVProgressHUD showErrorWithStatus:[resultDict objectForKey:@"Message"]];
                                            [self.delegate GetMyCommentSucces:0 array:nil page:0];
                                        }
                                    }
                                }
                              passmanger:^(NSURLSessionDataTask * _Nonnull manger) {
                                  
                              }
                             andprogress:^(NSProgress * _Nonnull CProgress) {
                                 
                             }];
        
    }
    return self;
}

@end
